package com.jy.service.filemanager.operlog;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jy.entity.filemanager.TSLog;
import com.jy.repository.filemanager.OperLogDao;
import com.jy.service.base.BaseServiceImp;

@Service("operLogService")
public class OperLogServiceImp extends BaseServiceImp<TSLog> implements
		OperLogService {

	@Override
	@Transactional
	public int creatLog(TSLog o) {
		int res = 0;
		try {
			o.setCreateDate(new Date());
			// 更新数据库
			super.insert(o);
			res = 1;
		} catch (Exception e) {
			logger.error("创建任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public int updateLog(TSLog o) {
		int res = 0;
		try {
			OperLogDao dao = (OperLogDao) baseDao;
			// 从数据库查找原信息
			dao.updateLog(o);
			res = 1;
		} catch (Exception e) {
			logger.error("创建任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public int deleteLog(TSLog o) {
		int res = 0;
		try {
			OperLogDao dao = (OperLogDao) baseDao;
			// 从数据库查找原信息
			dao.deleteLog(o);
			res = 1;
		} catch (Exception e) {
			logger.error("删除任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public TSLog findLogById(TSLog o) {
		OperLogDao dao = (OperLogDao) baseDao;
		// 从数据库查找原信息
		dao.findLogByPId(o.getId());
		return o;
	}
}
